package com.web.cms.pan.util;

import com.blue.core.util.NumberUtil;
import com.blue.jdbc.Page;
import com.web.cms.pan.message.UserInfoResponse;
import com.web.cms.pan.model.UserInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户网盘信息转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2018年04月09日
 */
public class UserInfoConvertor
{
	private UserInfoConvertor()
	{
	}
	
	public static UserInfoResponse toResponse(UserInfo userInfo)
	{
		if (userInfo == null)
			return null;
		
		UserInfoResponse response = new UserInfoResponse();
		response.setId(userInfo.getId());
		response.setPoint(userInfo.getPoint());
		response.setFiles(userInfo.getFiles());
		response.setFileSize(userInfo.getFileSize());
		response.setDeleteFiles(userInfo.getDeleteFiles());
		response.setDeleteFileSize(userInfo.getDeleteFileSize());

		response.setFileSizeName(NumberUtil.byteFormat(userInfo.getFileSize()));
		response.setDeleteFileSizeName(NumberUtil.byteFormat(userInfo.getDeleteFileSize()));
		return response;
	}
	
	public static List<UserInfoResponse> toResponse(List<UserInfo> list)
	{
		List<UserInfoResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (UserInfo userInfo : list)
		{
			responseList.add(toResponse(userInfo));
		}
		return responseList;
	}
	
	public static Map<Integer, UserInfoResponse> toResponse(Map<Integer, UserInfo> map)
	{
		Map<Integer, UserInfoResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, UserInfo> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<UserInfoResponse> toResponse(Page<UserInfo> page)
	{
		if (page == null)
			return null;
		
		Page<UserInfoResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
